<?php
session_start();
require_once('models/Image.class.php');
require_once("configs/db_connect.php");

$crop_data=$_POST;

$image=new Image();
$avatar = $image->createAvatar($crop_data);
if (!empty($avatar))
{
	 $avatar150 = $image->createAvatar150($avatar);
	 if (!empty($avatar150))
	{
		 $avatar50 = $image->createAvatar50($avatar150);		 
	}
}
$avatars=array
(
	 'avatar'=>$avatar, 
	 'avatar150'=>$avatar150, 
	 'avatar50'=> $avatar50 
);

$place_holder=array
(
	 'id'=>$_SESSION['user_id'],
	 'field'=>'',
	 'avatar'=>''
);

foreach ($avatars as $k=>$v)
{
	 $place_holder['field']=$k;
	 $place_holder['avatar']=$v;
	 
	 if (!empty($place_holder['avatar']))
	 {		 
		 SQL::execute(Template::render("updateUserAvatar.sql", "sql", $place_holder));	
	 }
}



?>
